import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { EffectManager } from "../../manager/EffectManager";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ResFileConst } from "../../resource/ResFileConst";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Cache } from "../../cache/Cache";
import { DataEvent } from "../../events/DataEvent";
import { BossFieldCliffordView } from "./BossFieldCliffordView";
import { BossFieldTopWindow } from "./BossFieldTopWindow";
import { SBossFieldMyScore } from "../../../../Message/Public/SBossFieldMyScore";
import { GameConst } from "../../../component/gconst/GameConst";
import { SNewBattleFieldInspireInfo } from "../../../../Message/Public/SNewBattleFieldInspireInfo";
import { ClockManager } from "../../manager/ClockManager";
import { Global } from "../../../../com/gengine/global/Global";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { SecTimerView } from "../common/SecTimerView";
type int = number;
//class BossFieldMiniScoreView
    
    export  class BossFieldMiniScoreView extends View
    {
        constructor()
        {
            super();
            layer = LayerManager.uiLayer;
            this.resetPos();
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnShowScore.addEventListener(flash.events.MouseEvent.CLICK, this.onClickShowScore);
            this._btnUp.addEventListener(flash.events.MouseEvent.CLICK, this.onClickUp);
            this._btnDown.addEventListener(flash.events.MouseEvent.CLICK, this.onClickDown);
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMoveBtnMouseUp);
            this._btnClifford.addEventListener(flash.events.MouseEvent.CLICK, this.onClickClifford);
            this._btnGet.addEventListener(flash.events.MouseEvent.CLICK, this.onClickGet);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResize);
            return;
        }

        public registBlink(arg1: Boolean): void
        {
            if (arg1) 
            {
                EffectManager.glowFilterReg(this._btnGet, null, 2);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this._btnGet);
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._spMiniScore = new Object /* flash.display.Sprite */();
            this._spMiniScore.mouseEnabled = false;
            this._spMiniScore.x = 0;
            this.addChild(this._spMiniScore);
            loc1 = new GTextFormat(FontUtil.songtiName, 12, 13563133);
            loc2 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(1).intColor);
            loc3 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(2).intColor);
            loc4 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(3).intColor);
            var loc5=new GTextFormat(FontUtil.songtiName, 12, 16711680);
            this._moveBtn = ObjCreate.createGButton("", 134, 0, 26, 23, this._spMiniScore, "MoveBtn");
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(41622), "#FFFFFF");
            var loc6;
            (loc6 = GlobalClass.getBitmap(ImagesConst.BattlefieldIconBgRight)).x = 86;
            loc6.y = 0;
            this._spMiniScore.addChild(loc6);
            this._btnShowScore = ObjCreate.createGLoadedButton(ResFileConst.BattleFieldResult, 0, 0, 114, 26, this._spMiniScore);
            this._btnUp = ObjCreate.createGButton("", 110, 0, 24, 25, this._spMiniScore, "BattlefieldIconUpBtn");
            this._btnDown = ObjCreate.createGButton("", 110, 0, 24, 25, null, "BattlefieldIconDownBtn");
            this._spExtend = new Object /* flash.display.Sprite */();
            this._spExtend.mouseEnabled = false;
            this._spMiniScore.addChild(this._spExtend);
            this._bottomBg = new ScaleBitmap(new Object /* flash.display.BitmapData */(160, 230, false, 0));
            this._bottomBg.alpha = 0.45;
            this._bottomBg.x = 0;
            this._bottomBg.y = 26;
            this._spExtend.addChild(this._bottomBg);
            this._tfMyKill = ObjCreate.createTextField(Language.getStringByParam(41623, "0"), 23, 30, 60, 20, this._spExtend, loc1);
            this._tfMyHonor = ObjCreate.createTextField(Language.getStringByParam(41624, "0"), 83, 30, 80, 20, this._spExtend, loc1);
            this._tfCamp1 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(1) + ":", 43, 50, 36, 20, this._spExtend, loc2);
            this._tfCamp2 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(2) + ":", 43, 70, 36, 20, this._spExtend, loc3);
            this._tfCamp3 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(3) + ":", 43, 90, 36, 20, this._spExtend, loc4);
            this._tfCamp1Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 50, 75, 20, this._spExtend, loc1);
            this._tfCamp2Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 70, 75, 20, this._spExtend, loc1);
            this._tfCamp3Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 90, 75, 20, this._spExtend, loc1);
            this._tfCountdown = ObjCreate.createSecTimeView(Language.getStringByParam(41627), 23, 110, 115, 20, this._spExtend, loc1);
            this._taskSp = new Object /* flash.display.Sprite */();
            this._taskSp.mouseEnabled = false;
            ObjCreate.setObjAttri(this._taskSp, 0, 130, -1, -1, this._spExtend);
            this._line = ObjCreate.createBg(5, 0, 158, 1, this._taskSp, ImagesConst.SeptalLine);
            ObjCreate.createTextField(Language.getString(44709), 5, 4, 150, 20, this._taskSp, GlobalStyle.textFormat1);
            this._taskCondition1 = ObjCreate.createTextField("", 65, 22, 90, 20, this._taskSp, GlobalStyle.textFormat1);
            this._taskCondition2 = ObjCreate.createTextField("", 65, 40, 90, 20, this._taskSp, GlobalStyle.textFormat1);
            this._taskCondition3 = ObjCreate.createTextField("", 65, 58, 90, 20, this._taskSp, GlobalStyle.textFormat1);
            this._tfReward = ObjCreate.createTextField("", 5, 76, 130, 20, this._taskSp, GlobalStyle.textFormat1);
            this._btnGet = ObjCreate.createGButton(Language.getString(44714), 118, 73, 40, 22, this._taskSp);
            this._cliffordSp = new Object /* flash.display.Sprite */();
            this._cliffordSp.mouseEnabled = false;
            ObjCreate.setObjAttri(this._cliffordSp, 0, 230, -1, -1, this._spExtend);
            this._line = ObjCreate.createBg(5, 0, 158, 1, this._cliffordSp, ImagesConst.SeptalLine);
            this._current = ObjCreate.createTextField(Language.getString(44715), 5, 5, 112, 20, this._cliffordSp, null, true);
            this._btnClifford = ObjCreate.createGButton(Language.getString(44716), 113, 2, 45, 22, this._cliffordSp, "ButtonRedMini");
            if (Cache.instance.bossField.inspireInfo) 
            {
                this.updateInspireInfo(Cache.instance.bossField.inspireInfo);
            }
            return;
        }

        /* internal  */stageResize(arg1: DataEvent): void
        {
            this.resetPos();
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMiniScore.startDrag();
            return;
        }

        /* internal  */onMoveBtnMouseUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMiniScore.stopDrag();
            return;
        }

        /* internal  */onClickClifford(arg1: Object /* flash.events.MouseEvent */): void
        {
            BossFieldCliffordView.instance.show();
            return;
        }

        /* internal  */onClickGet(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BossFieldGet));
            return;
        }

        /* internal  */onClickShowScore(arg1: Object /* flash.events.MouseEvent */): void
        {
            BossFieldTopWindow.instance.show();
            return;
        }

        /* internal  */onClickUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._btnUp.parent) 
            {
                this._btnUp.parent.removeChild(this._btnUp);
            }
            this._spMiniScore.addChild(this._btnDown);
            if (this._spExtend.parent) 
            {
                this._spExtend.parent.removeChild(this._spExtend);
            }
            return;
        }

        /* internal  */onClickDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._btnDown.parent) 
            {
                this._btnDown.parent.removeChild(this._btnDown);
            }
            this._spMiniScore.addChild(this._btnUp);
            this._spMiniScore.addChild(this._spExtend);
            return;
        }

        public updateTfCamp(): void
        {
            if (Cache.instance.bossField.isCrossBossField) 
            {
                this._tfCamp1.text = GameDefConfig.instance.getCrossBossFieldName(1) + ":";
                this._tfCamp2.text = GameDefConfig.instance.getCrossBossFieldName(2) + ":";
                this._tfCamp3.text = GameDefConfig.instance.getCrossBossFieldName(3) + ":";
            }
            else 
            {
                this._tfCamp1.text = GameDefConfig.instance.getECamp(1) + ":";
                this._tfCamp2.text = GameDefConfig.instance.getECamp(2) + ":";
                this._tfCamp3.text = GameDefConfig.instance.getECamp(3) + ":";
            }
            return;
        }

        public updateMyScore(arg1: SBossFieldMyScore): void
        {
            var loc1=false;
            this._bossFieldMyScore = arg1;
            this._tfMyKill.text = Language.getStringByParam(41623, arg1.killPlayer.toString());
            this._tfMyHonor.text = Language.getStringByParam(41624, arg1.honour.toString());
            if (arg1.haveTask) 
            {
                this._taskCondition1.htmlText = Language.getStringByParam(44710, arg1.killPlayer, GameConst.BossFieldTaskKillNum);
                this._taskCondition2.htmlText = Language.getStringByParam(44711, arg1.beKill, GameConst.BossFieldTaskBeKillNum);
                this._taskCondition3.htmlText = Language.getStringByParam(44712, arg1.assist, GameConst.BossFieldTaskAssistNum);
                this._tfReward.htmlText = Language.getStringByParam(44713, GameConst.BossFieldTaskHonourAward);
                this._bottomBg.height = 230;
                this._taskSp.visible = true;
                this._cliffordSp.y = 230;
                loc1 = arg1.killPlayer >= GameConst.BossFieldTaskKillNum || arg1.beKill >= GameConst.BossFieldTaskBeKillNum || arg1.assist >= GameConst.BossFieldTaskAssistNum;
                this._btnGet.enabled = loc1;
                this.registBlink(loc1);
            }
            else 
            {
                this._bottomBg.height = 130;
                this._taskSp.visible = false;
                this._cliffordSp.y = 130;
                this._btnGet.enabled = false;
                this.registBlink(false);
            }
            return;
        }

        public updateForceScore(arg1: int, arg2: int, arg3: int): void
        {
            var loc1=0;
            var loc5=0;
            this._tfCamp1Score.text = Language.getStringByParam(41626, arg1.toString());
            this._tfCamp2Score.text = Language.getStringByParam(41626, arg2.toString());
            this._tfCamp3Score.text = Language.getStringByParam(41626, arg3.toString());
            var loc2=[1, 2, 3];
            var loc3=[arg1, arg2, arg3];
            var loc4=0;
            while (loc4 < (loc3.length - 1)) 
            {
                loc5 = (loc3.length - 1);
                while (loc5 > loc4) 
                {
                    if (loc3[loc5] > loc3[(loc5 - 1)]) 
                    {
                        loc1 = loc2[loc5];
                        loc2[loc5] = loc2[(loc5 - 1)];
                        loc2[(loc5 - 1)] = loc1;
                        loc1 = loc3[loc5];
                        loc3[loc5] = loc3[(loc5 - 1)];
                        loc3[(loc5 - 1)] = loc1;
                    }
                    --loc5;
                }
                ++loc4;
            }
            this._tfCamp1Score.y = this.getScorePos(1, loc2);
            this._tfCamp2Score.y = this.getScorePos(2, loc2);
            this._tfCamp3Score.y = this.getScorePos(3, loc2);
            this._tfCamp1.y = this.getScorePos(1, loc2);
            this._tfCamp2.y = this.getScorePos(2, loc2);
            this._tfCamp3.y = this.getScorePos(3, loc2);
            return;
        }

        public updateInspireInfo(arg1: SNewBattleFieldInspireInfo): void
        {
            this._inspireInfo = arg1;
            var loc1=arg1.attackLevel;
            var loc2=GameDefConfig.instance.getBossfieldClifford(loc1);
            if (loc2) 
            {
                this._current.htmlText = Language.getStringByParam(44717, HTMLUtil.getHtmlByComp(loc2.name));
            }
            else 
            {
                this._current.htmlText = Language.getString(44715);
            }
            return;
        }

        /* internal  */getScorePos(arg1: int, arg2: Array<any>): int
        {
            if (arg1 == arg2[0]) 
            {
                return 50;
            }
            if (arg1 == arg2[1]) 
            {
                return 70;
            }
            return 90;
        }

        public startCountdown(arg1: Date): void
        {
            var loc1=(arg1.time - ClockManager.instance.nowDate.time) / 1000;
            this._tfCountdown.setLeftTime(loc1);
            return;
        }

        public stopCountDown(): void
        {
            this._tfCountdown.stop();
            return;
        }

        public resetPos(): void
        {
            this.x = Global.stage.stageWidth - 190;
            this.y = 194;
            return;
        }

        /* internal */ /* var */_taskCondition2: Object /* flash.text.TextField */;

        /* internal */ /* var */_taskCondition3: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfReward: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnGet: GButton;

        /* internal */ /* var */_tfMyHonor: Object /* flash.text.TextField */;

        /* internal */ /* var */_current: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnClifford: GButton;

        /* internal */ /* var */_bossFieldMyScore: SBossFieldMyScore;

        /* internal */ /* var */_inspireInfo: SNewBattleFieldInspireInfo;

        /* internal */ /* var */_btnShowScore: GLoadedButton;

        /* internal */ /* var */_cliffordSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_spMiniScore: Object /* flash.display.Sprite */;

        /* internal */ /* var */_spExtend: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bottomBg: ScaleBitmap;

        /* internal */ /* var */_tfMyKill: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp1: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp2: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp3: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp1Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp2Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp3Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_line: ScaleBitmap;

        /* internal */ /* var */_tfCountdown: SecTimerView;

        /* internal */ /* var */_btnUp: GButton;

        /* internal */ /* var */_btnDown: GButton;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_taskSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_taskCondition1: Object /* flash.text.TextField */;
    }
